package dao;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

public class BaseDao {
    public static String driver;
    public static String url;
    public static String username;
    public static String pwd;
    public static Connection conn;
    static {
        try {
            getProperties();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

    }


    public static void getProperties() throws IOException {
        Properties pr=new Properties();
        InputStream in=BaseDao.class.getClassLoader().getResourceAsStream("database.properties");
        pr.load(in);

        driver=pr.getProperty("driver");
        url=pr.getProperty("url");
        username=pr.getProperty("username");
        pwd=pr.getProperty("pwd");
    }


    public static void getConnection() throws ClassNotFoundException, SQLException {
        Class.forName(driver);
        conn= DriverManager.getConnection(url,username,pwd);
    }
}
